/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


$(function(){
    var shopnum = $("#shop-number");
    var ten_per = Math.floor(parseInt(shopnum.attr("data-max-number"))) || 1;
    var max_num = (ten_per > parseInt(shopnum.attr("data-remain-number"))) ? parseInt(shopnum.attr("data-remain-number")) : ten_per;
    shopnum.keyup(function(){
        if(shopnum.val()>=max_num){
            shopnum.val(max_num);
        }
        var numshop=shopnum.val();
        if(numshop==parseInt(shopnum.attr("data-max-number"))){
            var baifenbi='100%';
        }else{
            var showbaifen=numshop/parseInt(shopnum.attr("data-max-number"));
            var baifenbi=baifenshua(showbaifen,2);
        }
        $(".chance-per").text(baifenbi);
    });

    $("#number-up").click(function(){
        var resshopnump='';
        var ten_per = Math.floor(parseInt(shopnum.attr("data-remain-number"))) || 1;
        var num = parseInt(shopnum.val());
        if(num >= max_num){
            shopnum.val(max_num);
            resshopnump = max_num;
        }else{
            resshopnump=parseInt(shopnum.val())+1;
            shopnum.val(resshopnump);
        }
        if(resshopnump==parseInt(shopnum.attr("data-max-number"))){
            var baifenbi='100%';
        }else{
            var showbaifen=resshopnump/parseInt(shopnum.attr("data-max-number"));
            var baifenbi=baifenshua(showbaifen,2);
        }
        $(".chance-per").text(baifenbi);
    });
    $("#number-down").click(function(){
        var num = parseInt(shopnum.val());
        if(num<2){
            shopnum.val(1);			
        }else{
            shopnum.val(parseInt(shopnum.val())-1);
        }
        var shopnums=parseInt(shopnum.val());
        if(shopnums==parseInt(shopnum.attr("data-max-number"))){
            var baifenbi='100%';
        }else{
            var showbaifen=shopnums/parseInt(shopnum.attr("data-max-number"));
            var baifenbi=baifenshua(showbaifen,2);
        }
        $(".chance-per").text(baifenbi);
    });
    $(".Det-Shopbtn").click(function(){
        
        if(is_login.uuid==""){
            layer.msg("请先登录，再操作哦！",{icon:0,offset:300,time:2000});return;
        }
        Cartcookie(true);
    });
    var jia_btn=$(".J_jia"),jian_btn=$(".J_jian"),cart_number=$(".J_number"),xiaoji=$("#xj-number"),zongji=$("#zj-number");
    cart_number.keyup(function(){
        var self=$(this),number=self.val(),shopid=self.attr("data-shopid");
        if(number > info[shopid]['shenyu']){
            number = info[shopid]['shenyu'];
            self.val(number);
            updateMoney(shopid,number);
            return;
        }
        if(number < 2){
            number = 1;
            self.val(number);
            updateMoney(shopid,number);
            return;
        }
        self.val(number);
        updateMoney(shopid,number);
    });
    jia_btn.click(function(){
        var self=$(this),shopid=self.attr("data-shopid");
        var number=info[shopid]['num']+1;
        
        if(parseInt(number) > parseInt(cart_number.attr("data-remain-number"))){
            return;
        }
        cart_number.val(number);
        updateMoney(shopid,number);
        
    });
    jian_btn.click(function(){
        var self=$(this),shopid=self.attr("data-shopid");
        var number=info[shopid]['num']-1;	
        if(number < 2){
            number = 1;
        }
        cart_number.val(number);
        updateMoney(shopid,number);
    });
    $(".info-ok").click(function(){
        var countmoney=parseInt(zongji.text());		
        if(countmoney > 0){		
            $.cookie('CartShop',$.toJSON(info),{expires:30,path:'/'});
            document.location.href='/cart/mkorder.html';
        }else{
            layer.msg("参数有误!",{icon:0,offset:300,time:2000});
        }
    });
    function updateMoney(shopid,num){
        var number = parseInt(num);
        info['MoenyCount']=parseInt(info[shopid]['money'] * number);
        info[shopid]['num'] = number;
        xiaoji.text(number+" 个"),zongji.text(number);
    }
});
function baifenshua(aa,n){
    n = n || 2;
    return ( Math.round( aa * Math.pow( 10, n + 2 ) ) / Math.pow( 10, n ) ).toFixed( n ) + '%';
}
function Cartcookie(cook){
    var shopid = shopinfo['shopid'];
    var number=parseInt($("#shop-number").val());
    if(number<=1){number=1;}
    $.cookie('CartShop',"");
    var info={};
    info[shopid]={};
    info[shopid]['num']=number;
    info[shopid]['shenyu']=shopinfo['shenyu'];
    info[shopid]['money']=shopinfo['money'];
    info['MoenyCount']='0';	
    $.cookie('CartShop',$.toJSON(info),{expires:7,path:'/'});
    
    if(cook){
        window.location.href="/cart/cartlist/"+new Date().getTime();
    }
}  
function delcart(id){
    info['MoenyCount'] = 0;
    $("#shoplist-"+id).html("<td colspan='7' style='height:120px;' class=''>没有任何数据啦</td>");
    $("#zj-number").text("0");
    delete info[id];
    $.cookie('CartShop',$.toJSON(info),{expires:30,path:'/'});
}

$(function(){
    if(typeof(orderInfo) != "undefined"){
        if(orderInfo['userMoney'] >= orderInfo['moenyCount']){
            $("#thirdPlatPayList").hide();
            $("#moneyCheckbox").attr("checked",true);
            $("#moneyCheckbox").attr("disabled",true);
            $("#pay_money").text(orderInfo['moenyCount']);
	}
	
	if(orderInfo['userMoney']==0){
            $(".unenough").css("background","#eee");
            $(".unenough").children().css("color","#bcbcbc");
            $(".unenough").find(".how-balance").css("color","#bcbcbc");
            $("#moneyCheckbox").attr("disabled",true);
	}
	if(orderInfo['userMoney'] < orderInfo['moenyCount']){		
		$("#moneyCheckbox").attr("checked",true);
		$("#pay_money").text(orderInfo['userMoney']);
		$("#pay_bankmoney").text(orderInfo['moenyCount']-orderInfo['userMoney']);
		$("#moneyCheckbox").click(function(){
                    if(this.checked){
                        $("#pay_money").text(orderInfo['userMoney']);
                        $("#pay_bankmoney").text(orderInfo['moenyCount']-orderInfo['userMoney']);
                    }else{
                        $("#pay_money").text('0');
                        $("#pay_bankmoney").text(orderInfo['moenyCount']);	
                    } 
		});
	}
    }
    $("#submit_ok").click(function(){	
        if(!this.flag){
            this.flag = 1;		
            return true;
        }else{		
            return false;
        }		
        return false;
    });
});

function page_show_date_time_location(shop_id){
    window.setTimeout(function(){
        $.post("/lottery_shop_set",{"lottery_sub":"true","gid":shop_id},null);
        window.setTimeout(function(){window.location.href="/lottery_finish/"+shop_id+".html";},1000);
    },1000);
}

function run_time_show(T,O){
    var G = $("#goods-"+O).children(".product-progress"),
    B = G.children().find(".count-down");
    if(B.hasClass("cding")){
        return;
    }
    B.addClass("cding");
    var F = function(){
        t = T - (new Date().getTime());
        if (t <= 0) {
            G.html("<dd class='duobao-calculate mt10'><p>系统计算中...</p></dd>");
            page_show_date_time_location(O);
            $.ajaxSetup({
                async: false
            });
            $.post("/lottery/ajax_shop_set/", {
                'lottery_sub': 'true',
                'gid': O,
            }, function(data){
                window.setTimeout(function(){window.location.href="/lottery_finish/"+O+".html";},2000);
            });
            return;
        }
        i = parseInt((t / 1000) / 60);
        s = parseInt((t / 1000) % 60);
        m = String(Math.floor(t % 1000));
        m = parseInt(m.substr(0, 2));
        if (i < 10) i = '0' + i;
        if (s < 10) s = '0' + s;
        if (m < 0) m = '00';
        mr = new String(i);
        t1 = mr.substr(0,1);
        t2 = mr.substr(1,1);

        sd = new String(s);
        s1 = sd.substr(0,1);
        s2 = sd.substr(1,1);

        md = new String(m);
        m1 = md.substr(0,1);
        m2 = md.substr(1,1);

        B.children(".t_minuter1").text(t1);
        B.children(".t_minuter2").text(t2);
        B.children(".t_second1").text(s1);
        B.children(".t_second2").text(s2);
        B.children(".t_minsecond1").text(m1);
        B.children(".t_minsecond2").text(m2);

        setTimeout(function() {F();}, 30);
    }
    F();
}

(function($){
    

    var is = function(){
         
        var F = function(){
                var oul = ($("#art-marquee"))[0];
                var ali = oul.getElementsByTagName('li');
                var spa = -2;	
                var item = oul.innerHTML;
                oul.innerHTML=oul.innerHTML+oul.innerHTML;
                oul.style.width=ali[0].offsetWidth * ali.length+'px';
                
                function M(){
                    if(oul.offsetLeft < -oul.offsetWidth/2){
                        oul.style.left='0';
                    }
                    if(oul.offsetLeft > 0){
                        oul.style.left = -oul.offsetWidth/2+'px'
                    }
                    oul.style.left = oul.offsetLeft + spa +'px';
                }
                var T = setInterval(M,30);
                oul.onmousemove=function(){clearInterval(T);}
                oul.onmouseout=function(){T = setInterval(M,30)};
        }
         
        setTimeout(F,500);
    }
     
    var tf = function(T,O){
        var G = $("#goods-"+O).children().find(".product-progress"),
        B = G.children().find(".count-down");
        if(B.hasClass("cding")){
            return;
        }
        B.addClass("cding");
        var F = function(){
            t = T - (new Date().getTime());
            if (t <= 0) {
                G.html("<div class='duobao-calculate mt10'><p>系统计算中...</p></div>");
                setTimeout(function() {
                    $.ajaxSetup({
                        async: false
                    });
                    $.post("/lottery/ajax_shop_set/", {
                        'lottery_sub': 'true',
                        'gid': O,
                        'resp':true
                    }, function(data){
                        data = $.parseJSON(data);
                        var H = "<div class='duobao-winners mt10 pt10'>";
                            H += "   <a href='"+data.space_url+"' class='head'><img src='"+data.head_img+"'/></a>";
                            H += "   <div class='fr w184'>";
                            H += "       <p>幸运伙伴：<a href='"+data.space_url+"'>"+data.nickname+"</a>";
                            H += "       <p>幸运号码："+data.luck_code+"</p>";
                            H += "       <p>本期参与："+data.num+"人次</p>";
                            H += "       <p>揭晓时间："+data.time+"</p>";
                            H += "   </div>";
                            H += "</div>";
                        G.html(H);
                    });
                }, 3000);
                return;
            }
            i = parseInt((t / 1000) / 60);
            s = parseInt((t / 1000) % 60);
            m = String(Math.floor(t % 1000));
            m = parseInt(m.substr(0, 2));
            if (i < 10) i = '0' + i;
            if (s < 10) s = '0' + s;
            if (m < 0) m = '00';
            mr = new String(i);
            t1 = mr.substr(0,1);
            t2 = mr.substr(1,1);

            sd = new String(s);
            s1 = sd.substr(0,1);
            s2 = sd.substr(1,1);

            md = new String(m);
            m1 = md.substr(0,1);
            m2 = md.substr(1,1);

            B.children(".t_minuter1").text(t1);
            B.children(".t_minuter2").text(t2);
            B.children(".t_second1").text(s1);
            B.children(".t_second2").text(s2);
            B.children(".t_minsecond1").text(m1);
            B.children(".t_minsecond2").text(m2);
            
            setTimeout(function() {F();}, 30);
        }
        F();
    }
    
    var iu = function(){
        var O = $("#NewLuckyList"),
        C = O.children().find(".count-down");
        if(typeof(C) != "undefined" && C.length > 0){
            C.each(function(i,d){
                var I = $(d).parents("li").attr("data-id"),
                T = (parseInt($(d).attr("data-time"))) * 1000 + (new Date().getTime());
                tf(T,I);
            });
        }
    }
    iu();
    
    var n = function() {
        var B = $("#NewLuckyList");
        var z = 3;
        var D = false;
        var F = $("#maxSeconds").val();
        var A = null;
        var C = false;
        var E = function() {
            
            var G = function(I, J) {
                F = I.maxSeconds;
                if (C) {
                    return
                }
                var H = function(L, N) {
                    var S = L.length > z ? z : L.length;
                    var V = N.width();
                    var K = 0;
                    for (var R = S - 1; R >= 0; R--) {
                        var X = L[R];
                        if (N.children("li[id='goods-" + X.shopId + "']").length <= 0) {
                            var Q = "<li id='goods-"+X.shopId+"' data-id='"+X.shopId+"'>";
                               Q += "   <div class='p20'>";     
                               Q += "       <a href='"+X.detail_url+"' class='img'>";
                               Q += "           <img src='"+X.thumb+"'  width='254' height='160'/>";
                               Q += "       </a>";
                               Q += "       <a href='"+X.detail_url+"' class='name mt10'>"+X.title+"<b></b></a>";
                               Q += "       <p class='zongrenshu'>总需："+X.zongNum+" 人次</p>";
                               Q += "       <div class='product-progress'>";
                               Q += "           <div class='duobao-countdown mt10'>";
                               Q += "               <p class='title mb20 mt10'>即将揭晓：</p>";
                               Q += "               <div class='count-down' data-time='"+X.times+"'>";
                               Q += "               <b class='t_minuter1'>0</b>";
                               Q += "                 <b class='t_minuter2'>0</b>";
                               Q += "                 <em class='boss-red divide'>:</em>";
                               Q += "                 <b class='t_second1'>0</b>";
                               Q += "                 <b class='t_second2'>0</b>";
                               Q += "                 <em class='boss-red divide'>:</em>";
                               Q += "                 <b class='t_minsecond1'>0</b>";
                               Q += "                 <b class='t_minsecond2'>0</b>";
                               Q += "               </div>";
                               Q += "           </div>";
                               Q += "       </div>";
                               Q += "   </div>";
                               Q += "</li>";
                               
                            var T = $(Q);
                            N.prepend(T);
                            K++;
                            var O = T.width();
                            N.css({
                                width: V + K * O + "px"
                            });
                            N.css("marginLeft", -1 * K * O + "px");
                            tf((parseInt(X.times)) * 1000 + (new Date().getTime()),X.shopId);
                        }
                    }
                    N.children("li").each(function(Y) {
                        var Z = $(this);
                        if ((Y + 1) % 3 == 0) {
                            Z.addClass("curr-last")
                        }
                    });
                    if (K > 0) {
                        var W = N.parent();
                        W.css("border-left", "1px solid #eee");
                        W.css("border-right", "1px solid #eee");
                        W.css({
                            width: (W.width() - 4) + "px"
                        });
                        
                        C = true;
                        var P = K < 2 ? 1000 : 2000;
                        N.animate({marginLeft: "0px"},P,function() {
                            W.css("border-left", "none");
                            W.css("border-right", "none");
                            W.css({
                                width: 888 + "px"
                            });
                            for (var Y = 0; Y < K; Y++) {
                                N.children("li:last").remove()
                            }
                            N.css({
                                width: V + "px"
                            });
                            C = false
                        })
                    }
                };
                H(I.listItems,J);
            }
            
            $.ajaxSetup({
                async: false
            });
            $.post("/lottery/ajax_shop_done_json",{max_sincetime:F},
                function(H) {
                    H = $.parseJSON(H);
                    if (H.error == "0") {
                        G(H, B)
                    }
                    clearInterval(A);
                    A = null;
                    if(A == null){
                        A = setInterval(E, 5000);
                    }
            });
        };
        E();
    };
    
    if(typeof(($("#NewLuckyList")[0])) != "undefined"){
        setTimeout(n,30);
    }
    
    var s = function() {
        var H = $("#UserLuckyList");
        var I = H.children("li").length;
        var G = $("#LuBuyId").val();
        var A = 0;
        var B = 12;
        var C = 6;
        var z = 0;
        var F = function() {
            doRequest("/lottery/ajax_usre_duo_list",{buyId:G},false,
                function(O) {
                    if (O.count > 0) {
                        var N = O.data;
                        var P = H.children("li").length - C;
                        var J = N.length;
                        var M = "";
                        for (var L = (J - 1); L >= 0; L--) {
                            var K = "<li>";
                                K +=    "<div class='user-name'>";
                                K +=         "<a href='"+N[L].space_url+"'><img src='"+N[L].head_img+"'/>"+N[L].nickname+"</a>";
                                K +=         "<i class='num fr'>"+N[L].num+"人次</i>";
                                K +=    "</div>";
                                K +=    "<div class='txt'>";
                                K +=         "<a href='"+N[L].lottery_url+"' class='product-name'>"+N[L].title+"</a>";
                                K +=         "<i class='time fr'>"+N[L].time+"</i>";
                                K +=    "</div>";
                                K += "</li>";
                            if (L == 0) {
                                G = N[0].buy_id
                            }
                            M += K
                        }
                        H.prepend(M);
                        var J = 55;
                        H.css("marginTop", "-" + J + "px");
                        H.animate({
                            marginTop: "0px"
                        },
                        800)
                    }
                },function(){})
        };
        var E = function() {
            if (z >= 5) {
                z = 0;
                F()
            } else {
                z++
            }
        };
        var D = setInterval(E, 2000);
        H.hover(function() {
            clearInterval(D);
            D = null
        },function() {
            D = setInterval(E, 2000)
        })
    };
    var ul = $("#UserLuckyList");
    if(typeof(ul[0]) != 'undefined'){
        s();
    }
    var sl = $('.share-show ul li');
    if(typeof(sl[0]) != "undefined"){
        is();
    }
    
    var cs = function(){
        function animate(){
            ch.each(function(I,item){
            var C = parseInt($(item).attr('data-current')),
                T = parseInt($(item).attr('data-total'));
            var P = C == T ? 100 : parseInt((C/T)*100);
            $(item).animate({
                width: P+'%'},1000);
            });
        }
        animate();
    }
    
    var ch = $('.charts');
    if(typeof(ch[0]) != 'undefined'){
        cs();
    }
    
    var lm = function(){
        var S = 0,
        G = 0,
        SB = null,
        BB = null,
        SD = "",
        BD = "";
        var A = function(i){
            i = typeof(i) != "undefined" ? i : 0;
            SB.html("<tr><td colspan='6'><span class='load-tag'></span><td><tr>");
            setTimeout(function(){
                doRequest("/lottery/ajax_fetch_period",{pageIndex:i,shopId:S,stampTime:Math.random()},false,function(resp){
                    var TC = resp.data.totalCount;
                    var str = "";
                    if(TC == 0){
                        str += "<div class='tip-null'></div>";
                    }else{
                        var H = resp.data.listItems;
                        for (var L = 0; L < H.length; L++) {
                            var X = H[L];
                            str += "<tr>";
                            str += "    <td><a href='"+X.space_url+"' target='_blank'><img src='"+X.headImg+"' /><em>"+X.nickName+"</em></a></td>";
                            str += "    <td class='time'>"+X.time+"</td>";
                            str += "    <td><span>"+X.num+"</span></td>";
                            str += "    <td>第"+X.period+"期</td>";
                            str += "    <td>"+X.luckCode+"</td>";
                            str += "    <td><a href='"+X.lottery_url+"' target='_blank'>查看详情</a></td>";
                            str += "</tr>";
                        }
                    }
                    SB.html(str);
                    createPaginationModel({containerId:SD,perNum:12,currIndex:resp.data.pageIndex,totalCount:TC},A);
                },function(data){});
            },200);
        }
        
        var B = function(i){
            i = typeof(i) != "undefined" ? i : 0;
            BB.html("<tr><td colspan='5'><span class='load-tag'></span><td><tr>");
            setTimeout(function(){
                doRequest("/lottery/ajax_fetch_buy_list",{pageIndex:i,shopId:G,stampTime:Math.random()},false,function(resp){
                    var TC = resp.data.totalCount;
                    var str = "";
                    if(TC == 0){
                        str += "<div class='tip-null'></div>";
                    }else{
                        var H = resp.data.listItems;
                        for (var L = 0; L < H.length; L++) {
                            var X = H[L];
                            str += "<tr>";
                            str += "    <td><a href='"+X.space_url+"' target='_blank'><img src='"+X.headImg+"' /><em>"+X.nickName+"</em></a></td>";
                            str += "    <td class='time'>"+X.time+"</td>";
                            str += "    <td><span class='num'>"+X.num+"</span><label class='check check-code' data-rid='"+X.record_id+"'>查看号码</label></td>";
                            str += "    <td>"+X.ip+"</td>";
                            str += "</tr>";
                        }
                    }
                    BB.html(str);
                    createPaginationModel({containerId:BD,perNum:12,currIndex:resp.data.pageIndex,totalCount:TC},B);
                },function(data){});
            },200);
        }
        
        $(".load-more .old-period").on("click",function(){
            var _self = $(this);
            S = _self.attr("data-sid");
            SB = _self.parents(".list").children().find(".list-box");
            SD = _self.parent().attr("id");
            A();
        });
        
        $(".load-more .buy-list").on("click",function(){
            var _self = $(this);
            G = _self.attr("data-sid");
            BB = _self.parents(".list").children().find(".list-box");
            BD = _self.parent().attr("id");
            B();
        });
        $(".record-more").on("click",function(){
            $(".tab-list ul li.canyu").click();
            G = $(this).attr("data-sid");
            BB = $("#buy-list-box").find(".list-box");
            BD = "buy-list-pagenation";
            var t=$(".tab-list ul li.canyu").offset().top;
            $("html, body").stop(true,true).animate({scrollTop:(t-45)},800);
            B();
        });
        $("body").delegate('.participateIn table tr',"mouseenter",function(){
            $(this).find('.num').hide().siblings('.check').stop(true).fadeIn();
        }).delegate('.participateIn table tr',"mouseleave",function(){
            $(this).find('.check').hide().siblings('.num').stop(true).fadeIn();
        }).delegate('.tab-list ul li',"click",function(){
            index = $(this).index();
            $(this).addClass('active').siblings().removeClass('active');
            $(this).parents('.content').find('.tab-con .list').eq(index).fadeIn().siblings('.list').hide();
        });
        $(".count-more").click(function(){
            var S = $(this);
            if (S.hasClass("openup")){
                S.removeClass("openup");
                $(this).parent().children(".result-table").animate({height:"100%"},1000);
                $(this).text("收起 ↑").css("display","block");
            }else{
                S.addClass("openup");
                $(this).parent().children(".result-table").animate({height:"216px"},50);
                $(this).text("展开全部100条数据 ↓").css("display","block");
            }
        });
        $(".duo-fans-btn").click(function(){
            if(!_is_login()){return;};
            var _self=$(this),_fan=_self.attr("data-value"),_author_id=_self.attr("data-uid");
            if(is_login.uuid == _author_id){layer.msg("不能关注自己哦",{icon:0,offset:300,time:2000});return;}
            _fan=1-_fan;_self.attr("data-value",_fan);
            if(_fan==1){
                _self.removeClass("follow1").addClass("follow2").text("已关注");
            }else{
                _self.removeClass("follow2").addClass("follow1").text("+关注");;
                layer.msg("已取消关注",{icon:1,offset:300,time:1000});
            }
            doRequest("/ajax/cancel_fan_act",{author_id:_author_id,is_fan:_fan},true,function(data){},function(data){layer.msg(data.errorMsg,{icon:0,offset:300,time:2000});});
        });
    }
    lm();
    
    var cd = function(O){
        var A = $("body").find(".check-num"),
        L = A.children(".num-list"),
        N = A.children().find(".num");
        L.html(O.codeStr),N.text(O.codeNum);
        A.fadeIn(400);
        $(document.body).click(function(){
            A.fadeOut();
        });
    }
    
    $("body").delegate(".check-code","click",function(){
        var S = $(this),
        I = S.attr("data-rid");
        var L = function(){
            doRequest("/lottery/ajax_buy_code",{recordId:I},true,
                function(X){
                    cd(X);
                },function(X){});
        }
        L();
    });
    $(".see-code").on("click",function(){
        var S = $(this),
        I = S.attr("data-sid");
        var L = function(){
            doRequest("/lottery/ajax_user_code",{shopId:I},true,
                function(X){
                    cd(X);
                },function(X){});
        }
        L();
    });
    
    var nl = function(){
        var U = $("#ulLotteryList"),
            P = "lottery-pagination",
            C = $(".duobao-page-list"),
            N = 27,
            Z = null,
            t = 0;
        var G = function(M){
            var H = M.listItems;
            if(H.length > 0){
                t = M.maxSeconds;
                for(var a = (H.length - 1);a >= 0 ;a --){
                    var X = H[a];
                    if (U.children("li[id='goods-" + X.shopId + "']").length <= 0) {
                        var Q = "<li id='goods-"+X.shopId+"' data-id='"+X.shopId+"'>";
                           Q += "   <div class='p20'>";     
                           Q += "       <a href='"+X.detail_url+"' class='img'>";
                           Q += "           <img src='"+X.thumb+"'  width='254' height='160'/>";
                           Q += "       </a>";
                           Q += "       <a href='"+X.detail_url+"' class='name mt10'>"+X.title+"<b></b></a>";
                           Q += "       <p class='zongrenshu'>总需："+X.zongNum+" 人次</p>";
                           Q += "       <div class='product-progress'>";
                           Q += "           <div class='duobao-countdown mt10'>";
                           Q += "               <p class='title mb20 mt10'>即将揭晓：</p>";
                           Q += "               <div class='count-down' data-time='"+X.times+"'>";
                           Q += "               <b class='t_minuter1'>0</b>";
                           Q += "                 <b class='t_minuter2'>0</b>";
                           Q += "                 <em class='boss-red divide'>:</em>";
                           Q += "                 <b class='t_second1'>0</b>";
                           Q += "                 <b class='t_second2'>0</b>";
                           Q += "                 <em class='boss-red divide'>:</em>";
                           Q += "                 <b class='t_minsecond1'>0</b>";
                           Q += "                 <b class='t_minsecond2'>0</b>";
                           Q += "               </div>";
                           Q += "           </div>";
                           Q += "       </div>";
                           Q += "   </div>";
                           Q += "</li>";
                        var T = $(Q);
                        U.prepend(T);
                        tf((parseInt(X.times)) * 1000 + (new Date().getTime()),X.shopId);
                    }
                }
                U.children("li:gt(26)").remove();
            }
        }
        var E = function(){
            $.post("/lottery/ajax_shop_done_json",{max_sincetime:t},
                function(H) {
                    H = $.parseJSON(H);
                    if (H.error == "0") {
                        G(H)
                    }
            });
        }
        var M = function(O){
            var C = O.totalCount,
            L = O.listItems;
            if(C == 0){
                U.html("<div class='tip-null'></div>");
            }else{
                U.html("");
                for(var I = 0;I < L.length;I ++){
                    var X = L[I],H = "";
                    H += "<li id='goods-"+X.shopid+"' data-id='"+X.shopid+"'>";
                    H += "  <div class='p20'>";
                    H += "      <a href='"+X.lottery_url+"' target='_blank' class='img'><img src='"+X.thumb+"'  width='254' height='160'/></a>";
                    H += "      <a href='"+X.lottery_url+"' target='_blank' class='name mt10'>"+X.title+"<b></b></a>";
                    H += "      <p class='zongrenshu'>总需："+X.zongrenshu+" 人次</p>";
                    H += "      <div class='product-progress'>";
                    if(X.user != ""){
                        H += "      <div class='duobao-winners mt10 pt10'>";
                        H += "          <a href='"+X.user.space_url+"' target='_blank' class='head'><img  src='"+X.user.head_img+"'/></a>";
                        H += "          <div class='fr w184'>";
                        H += "              <p>幸运伙伴 ：<a href='"+X.user.space_url+"' target='_blank'>"+X.user.nickname+"</a></p>";
                        H += "              <p>幸运号码："+X.user.luck_code+"</p>";
                        H += "              <p>本期参与："+X.user.num+"人次</p>";
                        H += "              <p>揭晓时间："+X.user.time+"</p>";
                        H += "          </div>";
                        H += "      </div>";
                    }else{
                        H += "      <div class='duobao-countdown mt10'>";
                        H += "          <p class='title mb20 mt10'>即将揭晓：</p>";
                        H += "          <div class='count-down' data-time='"+X.times+"'>";
                        H += "              <b class='t_minuter1'>0</b>";
                        H += "              <b class='t_minuter2'>0</b>";
                        H += "              <em class='boss-red divide'>:</em>";
                        H += "              <b class='t_second1'>0</b>";
                        H += "              <b class='t_second2'>0</b>";
                        H += "              <em class='boss-red divide'>:</em>";
                        H += "              <b class='t_minsecond1'>0</b>"
                        H += "              <b class='t_minsecond2'>0</b>";
                        H += "          </div>";
                        H += "      </div>";
                    }
                    H += "      </div>";
                    H += "  </div>";
                    H += "</li>";
                    U.append(H);
                    if(X.user == ""){
                        var T = parseInt((X.times) * 1000 + (new Date().getTime()));
                        tf(T,X.shopid);
                    }
                }
                t = L[0].end_time;
                U.attr("max_sincetime",L[0].end_time);
            }
        }
        
        var F = function(I){
            I = typeof(I) == "undefined" ? 0 : I;
            if(I > 0){
                clearInterval(Z);
            }else{
                clearInterval(Z);
                Z = null;
                Z = setInterval(E,5000);
            }
            doRequest("/lottery/ajax_fetch_json",{pageIndex:I,stamptime:Math.random()},false,function(D){
                M(D.data);
                setTimeout(function(){
                    createPaginationModel({containerId:P,perNum:N,currIndex:D.data.pageIndex,totalCount:D.data.totalCount,num:6},F);
                },30);
                var t=$("body").find(U).offset().top;$("html, body").stop(true).animate({scrollTop:(t-100)},800);
            },function(data){});
        }
        
        F();
    }
    if(($("#ulLotteryList"))[0] != undefined){
        setTimeout(function(){nl()},30)
    }
    
    var bl = function() {
        var H = $("#userBuyNewList");
        var I = H.children("li").length;
        var G = $("#BuyNewListMaxId").val();
        var C = 6;
        var z = 0;
        var F = function() {
            doRequest("/lottery/ajax_usre_duo_list",{buyId:G},false,
                function(O) {
                    if (O.count > 0) {
                        var N = O.data;
                        var P = H.children("li").length - C;
                        var J = N.length;
                        var M = "";
                        for (var L = (J - 1); L >= 0; L--) {
                            var K = "<li>";
                                K += "    <a href='"+N[L].space_url+"' class='fl'><img src='"+N[L].head_img+"' /></a>";
                                K += "    <div class='buy-detail'>";
                                K += "        <p class='who-buying'><span><a href='"+N[L].space_url+"'>"+N[L].nickname+"</a></span><i>"+N[L].time+"购买了</i></p>";
                                K += "        <p class='buy-what'><a href='"+N[L].lottery_url+"'>"+N[L].title+"</a></p>";
                                K += "    </div>";
                                K += "    <div class='clear'></div>";
                                K += "</li>";
                            if (L == 0) {
                                G = N[0].buy_id
                            }
                            M += K
                        }
                        H.prepend(M);
                        var J = 72;
                        H.css("marginTop", "-" + J + "px");
                        H.animate({
                            marginTop: "0px"
                        },
                        800)
                    }
                },function(){})
        };
        var E = function() {
            if (z >= 2) {
                z = 0;
                F()
            } else {
                z++
            }
        };
        var D = setInterval(E, 2000);
        H.hover(function() {
            clearInterval(D);
            D = null
        },function() {
            D = setInterval(E, 2000)
        })
    };
    
    if(typeof(($("#userBuyNewList"))[0]) != "undefined"){
        bl();
    }
    
})(jQuery);